/**
 * 
 */
package com.ztesoft.sca.controller;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author pkc
 * 存放一些没有实现的接口，替换mockjs
 */
@RestController
public class UnDoApiList {
    
    
    /**
     * 通用数据对接
     * @param requestBody
     * @param request
     * @return
     * @throws NumberFormatException
     * @throws Exception
     */
    @RequestMapping(value = "/apitest/*.do",method = {RequestMethod.POST})
    public String api(@RequestBody String requestBody,HttpServletRequest request) throws NumberFormatException, Exception {
	System.out.println("-------------apitest-----------------");
	System.out.println(new String(requestBody.getBytes()));
	String uri = request.getRequestURI();
	String[] uris = uri.split("/");
	String datName = "com/ztesoft/sca/dataExample/"+uris[uris.length-1].replaceAll("\\.do", "")+".json";
	System.out.println(datName);
	InputStream in = UnDoApiList.class.getClassLoader().getResourceAsStream(datName);
	InputStreamReader isr = new InputStreamReader(in,"UTF8");
	BufferedReader br = new BufferedReader(isr);
	StringBuffer sb = new StringBuffer();
	while(true){
	    String line = br.readLine();
	    if(line==null){
		break;
	    }
	    sb.append(line);
	}
	System.out.println(sb.toString());
	System.out.println("-------------apitest-----end------------");
	return sb.toString();
    }
    
    
    
    /**
     * 登陆用
     * @param requestBody
     * @param request
     * @return
     * @throws NumberFormatException
     * @throws Exception
     */
    @RequestMapping(value = "/api1/user",method = {RequestMethod.POST})
    public String user(@RequestBody String requestBody,HttpServletRequest request) throws NumberFormatException, Exception {
	
	return null;
    }
    
    /**
     * 获取菜单
     * @return
     */
    @RequestMapping(value = "/api/menu",method = {RequestMethod.POST})
    public String menu(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    
    /**
     * 获取任务列表
     * @return
     */
    @RequestMapping(value = "/api1/jobTablejobList",method = {RequestMethod.POST})
    public String jobTablejobList(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    /**
     * 获取任务详情
     * @return
     */
    @RequestMapping(value = "/api1/jobTablejobDetail",method = {RequestMethod.POST})
    public String jobTablejobDetail(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    /**
     * 获取任务使用的数据集
     * @return
     */
    @RequestMapping(value = "/api1/jobTabledataSet",method = {RequestMethod.POST})
    public String jobTabledataSet(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    /**
     * 获取任务使用的规则质检结果
     * @return
     */
    @RequestMapping(value = "/api1/jobTableruleCheckResult",method = {RequestMethod.POST})
    public String jobTableruleCheckResult(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    /**
     * 获取任务文件质检结果
     * @return
     */
    @RequestMapping(value = "/api1/jobTableFileCheckResult",method = {RequestMethod.POST})
    public String jobTableFileCheckResult(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    /**
     * 获取质检场景列表
     * @return
     */
    @RequestMapping(value = "/api1/qcScene",method = {RequestMethod.POST})
    public String qcScene(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    /**
     * 获取规则列表
     * @return
     */
    @RequestMapping(value = "/api1/rule",method = {RequestMethod.POST})
    public String rule(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    /**
     * 获取规则列表
     * @return
     */
    @RequestMapping(value = "/api1/audioSrc",method = {RequestMethod.POST})
    public String audioSrc(@RequestBody String requestBody,HttpServletRequest request){
	return null;
    }
    
    
    
    public static void main(String[] args) throws IOException {
	File f = new File(UnDoApiList.class.getResource("/").getPath());
	System.out.println(f);
	//G:\gitlocal\sca_gx\target\classes\com\ztesoft\sca\dataExample
//	String datName = 
//		 "\\com\\ztesoft\\sca\\com\\ztesoft\\sca\\dataExample\\user.json";
	String datName = 
	 "com/ztesoft/sca/dataExample/user.json";
	System.out.println(datName);
	InputStream in = UnDoApiList.class.getClassLoader().getResourceAsStream(datName);
	InputStreamReader isr = new InputStreamReader(in,"gbk");
	BufferedReader br = new BufferedReader(isr);
	StringBuffer sb = new StringBuffer();
	while(true){
	    String line = br.readLine();
	    if(line==null){
		break;
	    }
	    sb.append(line);
	}
	System.out.println(sb.toString());
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
